package com.yt.demo.dto;

import com.yt.demo.constant.StatusCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 基本的返回对象
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BaseResp<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    private int code;

    private T data;

    private String msg;

    public static <T> BaseResp<T> success(T data, String msg) {
        return new BaseResp<>(StatusCode.SUCCESS_CODE, data, msg);
    }

    public static <T> BaseResp<T> success(T data) {
        return new BaseResp<>(StatusCode.SUCCESS_CODE, data, "success");
    }

    public static <T> BaseResp<T> error(T data, String msg) {
        return new BaseResp<>(StatusCode.ERROR_CODE, data, msg);
    }

    public static <T> BaseResp<T> error(T data) {
        return new BaseResp<>(StatusCode.ERROR_CODE, data, "error");
    }
}
